package com.avamanager.app.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.avamanager.common.annotation.Log;
import com.avamanager.common.core.controller.BaseController;
import com.avamanager.common.core.domain.AjaxResult;
import com.avamanager.common.enums.BusinessType;
import com.avamanager.app.domain.AppParent;
import com.avamanager.app.service.IAppParentService;
import com.avamanager.common.utils.poi.ExcelUtil;
import com.avamanager.common.core.page.TableDataInfo;

/**
 * 家长信息Controller
 * 
 * @author FenvyYe
 * @date 2022-08-24
 */
@RestController
@RequestMapping("/app/parent")
public class AppParentController extends BaseController
{
    @Autowired
    private IAppParentService appParentService;

    /**
     * 查询家长信息列表
     */
    @PreAuthorize("@ss.hasPermi('app:parent:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppParent appParent)
    {
        startPage();
        List<AppParent> list = appParentService.selectAppParentList(appParent);
        return getDataTable(list);
    }

    /**
     * 导出家长信息列表
     */
    @PreAuthorize("@ss.hasPermi('app:parent:export')")
    @Log(title = "家长信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppParent appParent)
    {
        List<AppParent> list = appParentService.selectAppParentList(appParent);
        ExcelUtil<AppParent> util = new ExcelUtil<AppParent>(AppParent.class);
        util.exportExcel(response, list, "家长信息数据");
    }

    /**
     * 获取家长信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:parent:query')")
    @GetMapping(value = "/{parentId}")
    public AjaxResult getInfo(@PathVariable("parentId") Long parentId)
    {
        return AjaxResult.success(appParentService.selectAppParentByParentId(parentId));
    }

    /**
     * 新增家长信息
     */
    @PreAuthorize("@ss.hasPermi('app:parent:add')")
    @Log(title = "家长信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppParent appParent)
    {
        return toAjax(appParentService.insertAppParent(appParent));
    }

    /**
     * 修改家长信息
     */
    @PreAuthorize("@ss.hasPermi('app:parent:edit')")
    @Log(title = "家长信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppParent appParent)
    {
        return toAjax(appParentService.updateAppParent(appParent));
    }

    /**
     * 删除家长信息
     */
    @PreAuthorize("@ss.hasPermi('app:parent:remove')")
    @Log(title = "家长信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{parentIds}")
    public AjaxResult remove(@PathVariable Long[] parentIds)
    {
        return toAjax(appParentService.deleteAppParentByParentIds(parentIds));
    }
}
